<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <title>稻道工场 社区粮店</title>
    <link rel="stylesheet" href="/thinkphp/Public/home/css/reset.css" />
    <link rel="stylesheet" href="/thinkphp/Public/home/css/store.css" />
    <script type="text/javascript" src="/thinkphp/Public/home/js/zepto.min.js" ></script>
    <script src="/thinkphp/Public/home/js/swiper.min.js"></script>
</head>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1, maximum-scale=1">
    <title>搜索</title>
    <link rel="stylesheet" href="/thinkphp/Public/home/css/reset.css" />
    <link rel="stylesheet" href="/thinkphp/Public/home/css/store.css" />
    <script type="text/javascript" src="/thinkphp/Public/home/js/zepto.min.js" ></script>
</head>
<body>
<div class="layout">
    <!--header-->
    <div class="wrapper">
        <div class="header">
            <a class="s_preson" href="<?php echo U('Index/index');?>" target="_blank"> < </a>
            <div class="store">
                搜索
            </div>
            <div class="s_preson_right">
                <i class="s_icon s_preson_right_btn"></i>
            </div>
        </div>
    </div>

    <div class="s_search_box">
        <form action="<?php echo U('Search/index');?>" method="post">
            <input class="s_searchBox" type="text" name="search"/>
            <input type="submit" class="s_searchBtn" value="搜索" />
        </form>
    </div>
    <div class="s_goods storeMain">
        <div class="storeBox">
            <?php if(is_array($SearchProduct)): $i = 0; $__LIST__ = $SearchProduct;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$ko): $mod = ($i % 2 );++$i;?><div class="list-item">
                    <div class="list-img"><a href="<?php echo U('Good/GoodInfo',array('id'=>$ro[id]));?>"><img src="/thinkphp/Uploads/thumb/<?php echo ($ko["thumb"]); ?>" alt="" width="100"/></a><i>√赠</i><div class="arrow-up"></div></div>
                    <div class="list-content">
                        <a href="<?php echo U('Good/GoodInfo',array('id'=>$ro[id]));?>"><h3 class="list-title"><?php echo ($ko["name"]); ?></h3></a>
                        <p class="list-price"><em>$<?php echo ($ko["shop_price"]); ?></em>&nbsp;</p>
                        <div class="list-main">微信支付<span>立减<i><?php echo ($ko["promote_price"]); ?></i>元</span></div>
                        <div class="list-add"><em class="prev" data="<?php echo ($ko["id"]); ?>">-</em><input type="text" size="5" value="1"><em class="next" data="<?php echo ($ko["id"]); ?>">+</em></div>
                    </div>
                </div><?php endforeach; endif; else: echo "" ;endif; ?>
        </div>
    </div>

    <div class="addUp">
        <div class="s_shopping"><i class="s_icon s_up"></i><em id="cartNum"><?php echo ($cartNum); ?></em></div>
        <div class="total">总计:<p>$<em id="cartPrice"><?php echo ($cartPrice); ?></em></p></div>
        <div class="settlement"><a href="<?php echo U('Order/cart');?>">去结算</a></div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    $(function(){
        (function(){
            var searchBtn  = $('.s_search_box');
            var searchTxt =  searchBtn.find('.s_searchBox');

            searchTxt.val('请输入商品名称');
            var val = searchTxt.val();

            searchTxt.focus(function(){
                var curVal = $(this).val();
                if(val==curVal){
                    $(this).val('')
                }else if(curVal==''){
                    $(this).val(val);
                }

            });
            searchTxt.blur(function(){
                var curVal = $(this).val();
                if(curVal==''){
                    $(this).val(val);
                }
            });

            //商品加减统计
            var listItem = $('.list-content');
            var listAdd  = listItem.find('.list-add');
            for(var i=0;i<listItem.length;i++){
                fnMain(listItem.eq(i));
            };

            function fnMain(quantityCur){
                var oPrev = quantityCur.find('.prev');
                var oNext  =   quantityCur.find('.next');
                var formInput =   quantityCur.find('input');

                var num=0;

                function showHide(){
                    if(num==0){
                        oPrev.css({'display':'none'});
                        formInput.css({'display':'none'});
                    }else{
                        oPrev.css({'display':'inline-block'});
                        formInput.css({'display':'inline-block'});
                    }
                }

                oPrev.click(function(){
                    if(num>0){
                        num--;
                    };
                    showHide();
                    formInput.val(num);
                    var productID=oPrev.attr("data");
                    var number=num;
                    $.ajax({
                        url:"<?php echo U('Index/addCart');?>",

                        type: 'POST',

                        data:{
                            productID:productID,
                            number:number
                        },

                        dataType: 'html',

                        timeout: 1000,

                        error: function(){alert('Error loading PHP document');},

                        success: function(result){
                            var one=result.split("/");
                            $("#cartNum").html(one[0]);
                            $("#cartPrice").html(one[1]);
                        }

                    });
                });



                oNext.click(function(){
                    num++;
                    showHide();
                    formInput.val(num);

                    var productID=oNext.attr("data");
                    var number=num;
                    $.ajax({
                        url:"<?php echo U('Index/addCart');?>",

                        type: 'POST',

                        data:{
                            productID:productID,
                            number:number
                        },

                        dataType: 'html',

                        timeout: 1000,

                        error: function(){alert('Error loading PHP document');},

                        success: function(result){
                            var one=result.split("/");
                            $("#cartNum").html(one[0]);
                            $("#cartPrice").html(one[1])
                        }

                    });
                });
            };
        })();
    })
</script>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
</html>